package com.cn.server.handler.websocket;

import com.cn.common.core.FastJsonUtils;
import com.cn.common.core.model.Request;
import com.cn.common.core.model.Result;
import com.cn.common.core.session.Session;
import com.cn.server.msg.MessageHandler;
import com.cn.common.module.login.request.LoginRequest;
import com.cn.server.module.login.handler.UserHandler;
import com.cn.server.module.login.handler.UserHandlerImpl;

import java.nio.charset.Charset;

/**
 * 登录handler
 */
public class WebSocketLoginHandler implements MessageHandler {

    private UserHandler userHandler = new UserHandlerImpl();

    @Override
    public Result<?> handle(Request packet, Session session) {
        String json = new String(packet.getData(), Charset.defaultCharset());
        LoginRequest loginRequest = FastJsonUtils.fromJson(json, LoginRequest.class);
        return userHandler.login(session, loginRequest.getBytes());
    }
}
